package com.pro.dl.dao.service;

import com.pro.dl.exception.PersonAlreadyExists;
import com.pro.dl.exception.StorageException;
import com.pro.dl.exception.UserDoesNotExists;
import com.pro.dl.pojo.Person;
import com.pro.dl.pojo.profile.PersonType;

/**
 * User related dao service
 * 
 * @author pankaj
 * 
 */
public interface PersonDao {

	/**
	 * Search person by given username. Return null if not found.
	 * 
	 * @param person
	 * @return
	 * @throws StorageException
	 */
	public Person searchPersonByUserName(String userName)
			throws StorageException;

	/**
	 * Search by personid. Returns null if not found.
	 * 
	 * @param personId
	 * @return
	 * @throws StorageException
	 */
	public Person searchPersonById(long personId) throws StorageException;
	
	/**
	 * Search personType by its personId.
	 * @param personTypeId
	 * @return
	 * @throws StorageException 
	 */
	public PersonType getPersonTypeById(long personTypeId) throws StorageException;
	
	/**
	 * Search PersonType by its name.
	 * @param name
	 * @return
	 * @throws StorageException 
	 */
	public PersonType searchPersonTypeByName(String name) throws StorageException;

	/**
	 * This is exclusively for updating existing person into database. If person
	 * does not found in database then {@code UserDoesNotExists} will be thrown.
	 * Person will be searched in database by person id, email, phonenumber or
	 * anything that is declared as unique.
	 * 
	 * @param person
	 * @return
	 * @throws StorageException
	 * @throws PersonAlreadyExists
	 */
	public Person updatePerson(Person person) throws StorageException,
			UserDoesNotExists;

	/**
	 * Create a new entry in person table if its already not there. If found
	 * already in database then {@code PersonAlreadyExists} will be thrown.
	 * Returns inserted person with id populated.
	 * 
	 * @param person
	 * @return
	 * @throws StorageException
	 * @throws PersonAlreadyExists
	 */
	public Person savePerson(Person person) throws StorageException,
			PersonAlreadyExists;

	/**
	 * As name suggests it is used to update password of a user given its
	 * username.
	 * 
	 * @param userName
	 * @param password
	 * @throws StorageException
	 * @throws UserDoesNotExists
	 */
	public void overridePassword(String userName, String password)
			throws StorageException, UserDoesNotExists;

	/**
	 * Validate a person through its token. Used for signup validation.
	 * 
	 * @param userName
	 * @param token
	 * @return
	 * @throws StorageException
	 * @throws UserDoesNotExists
	 */
	public Person validateUser(String userName, String token)
			throws StorageException, UserDoesNotExists;

	/**
	 * 
	 * @param result
	 * @throws StorageException
	 */
	public Person validatePassword(String userName, String password)
			throws StorageException;

	/**
	 * 
	 * @param userName
	 * @param question
	 * @param answer
	 * @return
	 * @throws StorageException
	 * @throws UserDoesNotExists
	 */
	public Person validateQNA(String userName, String question, String answer)
			throws StorageException, UserDoesNotExists;
}
